package cn.wolfcode.mp.test;


import cn.wolfcode.mp.domain.Employee;
import cn.wolfcode.mp.mapper.EmployeeMapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class UpdateTest2 {

    @Autowired
    private EmployeeMapper employeeMapper;
    @Test
    public void testSave(){
        Employee employee = new Employee();
        employee.setAdmin(1);
        employee.setAge(18);
        employee.setDeptId(1L);
        employee.setEmail("dafei@wolfcode");
        employee.setName("dafei");
        employee.setPassword("111");
        employeeMapper.insert(employee);
    }



    //需求： 将id=1用户名字修改为dafei
    @Test
    public void testUpdateById(){
        Employee employee = new Employee();
        employee.setId(1L);
        employee.setName("dafei");
        employeeMapper.updateById(employee);
    }

   // 需求：更新name=dafei员工年龄为18岁
    @Test
    public void testUpdate2(){
        //update 语句中的where 条件包装类
        UpdateWrapper<Employee> wrapper = new UpdateWrapper<>();

        wrapper.eq("name", "dafei").set("age", 18);

        employeeMapper.update(null, wrapper);
    }
}